//index.js
//获取应用实例
var http = require("../../utils/http.js");
var config = require("../../utils/config.js");


Page({
  data: {
    indicatorDots: true,
    indicatorColor: '#d1e5fb',
    indicatorActiveColor: '#1b7dec',
    autoplay: true,
    interval: 2000,
    duration: 1000,
    indexImgs: [],
    seq: 0,
    news: [],
    taglist: [],
    sts: 0,
    categoryList:[],
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function() {
    this.getAllData();
  },

  // 页面滚动到指定位置指定元素固定在顶部
  onPageScroll: function(e) { //监听页面滚动
    this.setData({
      scrollTop: e.scrollTop
    })
  },

  toProdPage: function(e) {
    var prodid = e.currentTarget.dataset.prodid;
    if (prodid) {
      wx.navigateTo({
        url: '/pages/prod/prod?prodid=' + prodid,
      })
    }
  },



  // 跳转搜索页
  toSearchPage: function() {
    wx.navigateTo({
      url: '/pages/search-page/search-page',
    })
  },

  //跳转商品活动页面
  toClassifyPage: function(e) {    
    var url = '/pages/prod-material/prod-material?sts=' + e.currentTarget.dataset.sts;
    var id = e.currentTarget.dataset.id;
    var title = e.currentTarget.dataset.title;  
    if (id) {
      url += "&tagid=" + id + "&title=" + title;
    }
    console.log('index页面跳转到其它页面'+url);    
    wx.navigateTo({
      url: url
    })
  },

 

  onShow: function() {
  },
  getAllData() {  
    this.getCategoryList();
  }, 

  getCategoryList() {
    // 加载分类
    var params = {
      url: "/category/categoryInfo",
      method: "GET",
      data: {
        parentId: '',
        categoryType: 3
      },
      callBack: (res) => {
        console.info(res);
        this.setData({
          categoryList: res,
        });
      }
    };
    http.request(params);
  },

  onPullDownRefresh: function() {

    // wx.showNavigationBarLoading() //在标题栏中显示加载

    //模拟加载
    var ths = this;
    setTimeout(function() {

      ths.getAllData();

      // wx.hideNavigationBarLoading() //完成停止加载

      wx.stopPullDownRefresh() //停止下拉刷新

    }, 100);

  },

  /**
   * 跳转至商品详情
   */
  showProdInfo: function(e) {
    let relation = e.currentTarget.dataset.relation;
    if (relation) {
      wx.navigateTo({
        url: 'pages/prod/prod',
      })
    }
  }
})